<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>试吃订单列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</head>
<body>

<div class="container">

    <div class="comm_crub">
        <span class="now_crub">试吃订单列表</span>
    </div>
    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                        <table >
                            <tbody>

                            <tr>
                                <td>
                                    订单编号：<input type="text" class="form-control input-sm w150" name="bill_code" maxlength="20">
				    <input type="hidden" name="sc" value="sc10">
                                    <input type="hidden" name="cityid" value="<!--{$city_id}-->">
                                </td>
                                <td>
                                    大客户名称：<input type="text" class="form-control input-sm w150" name="company_name" maxlength="30" value="<!--{$custID|default:''}-->">
                                </td>

                                <td>
                                    配送日期：<input class="form-control input-sm w85" id="send_date" name="send_date" value="" readonly="readonly" type="text" />
                                    <button type="button" class="btn btn-default btn-sm" onclick="bill.timeClear2();">清 空</button>
                                </td>
                                <td>
                                    下单日期：<input class="form-control input-sm w100" id="startDate" name="startDate" value="" readonly="readonly"   type="text" />
                                    ～
                                    <input class="form-control input-sm w100" id="endDate" name="endDate" value="" readonly="readonly" type="text"  />
                                    <button type="button" class="btn btn-default btn-sm" onclick="bill.timeClear1();">清 空</button>
                                </td>
                                <td>是否审核：<select name="bill_status_9" id="bill_status_9" class="form-control input-sm">
                                       <option value="">请选择</option>
                                       <option value="no">未审核</option>
                                       <option value="yes">已审核</option>
                                </select>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    城　　市：<select class="form-control input-sm" name="deliver_cityid" id="deliver_cityid">
                                        <option value="">请选择</option>
                                        <!--{if isset($city_array)}-->
                                        <!--{foreach from=$city_array item=city}-->
                                        <option value="<!--{$city.id}-->"><!--{$city.name}--></option>
                                        <!--{/foreach}-->
                                        <!--{/if}-->
                                    </select>
                                </td>
                                <td>
                                    订单类型：<select class="form-control input-sm" name="billType">
                                        <!--{foreach from=$global_array.bill_type item=bill_type_name key=bill_type}-->
                                        <!--{if $bill_type==9 }-->
                                        <option value="<!--{$bill_type}-->"><!--{$bill_type_name.name}--></option>
                                        <!--{/if}-->
                                        <!--{/foreach}-->
                                    </select>
                                </td>
                                <td colspan="3">

                                       <span>
                                        部 门：
                                    </span>
                                    <span style="vertical-align: middle">
                                        <div class="search_option">
                                            <div class="search_option_drop" >
                                                <span id="searchOptions">
                                                    请选择
                                                <font class="imageSites"><img src="/quanliadmin/docroot/images/comm/selects.jpg"></font>
                                                </span>
                                            </div>

                                            <ul class="search_option_panel"  id="searchPanels" style="display: none;z-index: 100;">
                                                <li class="childSelectImg" departmentID="" style="margin-top:5px;margin-bottom:5px;margin-left: 0px;font-size: 13px;" >请选择</li>
                                                <!--{$department_select_html}-->
                                            </ul>

                                            <input type="hidden" value="0" id="hdnSearchTypes" name="hdnSearchType">
                                            <input type="hidden" value="" id="search_departmentID" name="search_departmentID">
                                            <!--<input type="hidden" value="" id="departmentName" name="departmentName">-->
                                        </div>
                                    </span>
                                    <span>
                                   销售员：<select class="form-control w150" id="userID" name="userID">
                                            <option value="">请选择</option>
                                        </select>
                                </span>
                                    &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-primary btn-sm" onclick="bill.search();">查 询</button>&nbsp;&nbsp;
                                    <button type="button" class="btn btn-warning btn-sm" onclick="bill.clear();">重 置</button>&nbsp;&nbsp;
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>


</div>
<div id="pop" style="display: none;">

    <form class="form-horizontal" id="ticketForm" onsubmit="return false;">

        <div class="form-group">
            <label for="invoice_number" class="col-sm-3 control-label"><span class="red">*</span> 发票号：</label>
            <div class="col-sm-9">
                <input type="text" class="form-control w300" id="invoice_number" name="invoice_number" maxlength="100" />
                <input type="hidden" id="bill_no" name="bill_no" value="" />
            </div>
        </div>

    </form>

</div>
<script type="text/javascript">

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/bill/billSearch.ajax?operFlg=9",
        dataType: "json",
        colModel : [
            {display: "操作", width : 150, align: "center"},
            {display: "订单编号", name : "bill_no", width : 140, sortable : true, align: "center"},

            {display: "订单状态", width : 80},


            {display: "到货时间", width : 200},
            {display: "下单时间", width : 140, align: "center"},
            {display: "商品明细", width : 100},
            {display: "商品数量", width : 80},

            {display: "客户名称", width : 100},
            {display: "客户部门", width : 100},
            {display: "客户联系人", width : 100},
            {display: "联系方式", width : 100},

            {display: "详细地址", width : 180},
            {display: "企业人数", width : 80},
            {display: "试吃人数", width : 80},

            {display: "收货人手机号码", width : 120, align: "center"},
            {display: "收货人", width : 120}




        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加订单", bclass: "add", onpress : "bill.add"}
        ],
        <!--{/if}-->
        sortname: "bill_no",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        autoload: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var bill = {
        //取消试吃订单
        display: function(zt,billStatus) {
            var reject='';
            var html = "<form method=\"post\" id=\"messageForm\" name=\"messageForm\">";
            html += "<table>";
            html += "<tr>";
            html += "<td width=\"90\">留言：</td>";
            html += "<td width=\"*\">";
            html += "<textarea class='form-control' id=\"Remark\" name=\"Remark\" style=\"width:300px;height:100px;\"></textarea>";
            html += "</td>";
            html += "</tr>";
            if(billStatus==0){
              html += "<tr>";
              html += "<td width=\"90\">大客户状态：</td>";
              html += "<td><input name=\"reject\" id=\"reject\" type=\"radio\" value=\"reject\" />不可修改&nbsp;&nbsp;&nbsp;<input name=\"reject\"  type=\"radio\" value=\"rejectEdit\" id=\"rejectEdit\" checked=\"checked\"/>可修改</td>";
              html += "</td>";
              html += "</tr>";
              html += "<tr>";
              html += "<td colspan=\"2\" style=\"font-size:10px;color:red;padding: 0px;\">(*驳回后大客户信息的可操作状态)</td>";
              html += "</tr>";
            }
            html += "</tbody>";
            html += "</table>";
            html += "</form>";
            
            E.popup.open({
                title: "添加备注",
                content: html,
                btnName: "保存",
                btnCall: "bill.addInnerWord('"+zt+"');",
                css: 'width: 500px;'
            });

        },
        addInnerWord: function(zc) {
        //订单留言
        var remark = $('#Remark').val();
        if (!remark) {
            E.alert('请输入留言内容');
            return false;
        }
        var rejectc='';
        var radio=document.getElementsByName("reject");
            for(var i=0;i<radio.length;i++){
            if(radio[i].checked==true){
            rejectc=radio[i].value;
            break;
          }
         }
        $.ajax({
            type: "POST",
            url: "/invokingAjax-backend/bill/bill.ajax?operFlg=2",
            dataType: "JSON",
            data: {
                remark: remark,
                bill_no: zc
            },
            success: function( o ) {
                if (o.code == 200) {
                    E.popup.close();
                    var wordHtml = '<li class="list-group-item">[' + o.data.createTime + '] <span style="color: #666699;">'+ o.data.creator + '</span>:&nbsp;' + o.data.remark + '</li>';
                    $('#innerWordTb').append(wordHtml);
                } else {
                    E.alert(o.message);
                }
            }
        });
        E.ajax_get({
            url: "/invokingAjax-backend/bill/bill.ajax?operFlg=4",
            data: {
                bill_no: zc,
                rejectType:rejectc
            },
            call: "bill.result"
        });

    },
       
        search: function() {
            var dt = $("#search_form").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },

        clear: function() {
            $("#search_departmentID").val('');
            var searchOptions= "请选择" +'<font class="imageSites"><img src="/quanliadmin/docroot/images/comm/selects.jpg"></font>';
            $('#searchOptions').html( searchOptions );
            document.getElementById('search_form').reset();
            this.search();
        },

        timeClear1: function() {
            $('#startDate').val('');
            $('#endDate').val('');
        },
        timeClear2: function() {
            $('#send_date').val('');
        },

        audit: function( bill_no ) {
            this.bill_no = bill_no;
            E.confirm("您确认审核该订单吗？", "bill.confirmAudit");
        },

        confirmAudit: function() {
            E.ajax_get({
                url: "/invokingAjax-backend/bill/bill.ajax?operFlg=3",
                data: {
                    bill_no: this.bill_no
                },
                call: "bill.result"
            });
        },

        result: function( o ) {
            if (o.code == 200) {
                E.alert(o.message, 2);
                bill.search();
            } else {
                E.alert(o.message);
            }
        },

        add: function() {
            window.open("/quanliadmin/app/callcenter/callcenter.pscript?operFlg=1&operateType=1");
        },

        alter: function(bill_no) {
            window.open('/quanliadmin/app/bill/billEdit.pscript?operFlg=1&bill_no=' + bill_no);
        },

        cancel: function( bill_no ) {
            this.bill_no = bill_no;
            E.confirm("您确认取消该订单吗？", "bill.confirmCancel");
        },

        confirmCancel: function() {
            E.ajax_get({
                url: "/invokingAjax-backend/bill/bill.ajax?operFlg=4",
                data: {
                    bill_no: this.bill_no
                },
                call: "bill.result"
            });
        },

        //退货
        returnGoods : function( bill_no ) {
            window.open("/quanliadmin/app/bill/billReturn.pscript?operFlg=2&bill_no=" + bill_no);
        },

        //开发票
        makeTicket: function( bill_no ){
            $('#bill_no').val(bill_no);
            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"pop",   		 //获取id为"pop"元素内的HTML
                title: "开发票",       //弹出层标题
                css: "width:800px;",     //设置弹出层样式
                btnName: "保存",         //执行“确定”操作的按钮名称
                btnCall:"bill.check();"  //点击确定后执行的方法
            });
        },
        //验证发票
        check: function(){

            this.dt = E.getFormValues("ticketForm");
            var invoice_number = $.trim( $("#invoice_number").val() );
            var err_msg = '';

            if(invoice_number == ''){
                err_msg += '发票号不能为空，请填写<br />';
            }

            if(err_msg != ''){
                E.alert(err_msg);
            }else{
                bill.execute();
            }
        },

        //开票执行
        execute: function(){
            E.popup.close();
            E.loadding.open("正在保存，请稍候...");
            E.ajax_post({
                url: "/invokingAjax-backend/bill/billSearch.ajax?operFlg=100",
                data: this.dt,
                call: "bill.result"
            });
        },

        //返回结果
        result:function(o){
            if (o.code == 200) {
                E.alert(o.message, 2, "bill.load");
            } else {
                E.alert(o.message);
            }
            E.loadding.close();
        },

        load: function() {
            $("#flex").flexReload();
        }

    };

    $('#startDate').datepicker();
    $('#endDate').datepicker();
    $('#send_date').datepicker();

    $(function() {

        $('#deliver_cityid').change(function() {
            var deliver_cityid = $(this).val();
            if (deliver_cityid == '') {
                $('#distribution_id').html('<option value="">请选择</option>');
            } else {
                E.ajax_get({
                    url: '/invokingAjax-comm/bill/distribution.ajax?operFlg=2',
                    data: {
                        deliver_cityid: deliver_cityid,
                        no_act: 1
                    },
                    call: function( o ) {
                        $('#distribution_id').html('<option value="">请选择</option>');
                        if (o.data) {
                            $.each(o.data, function(k, v) {
                                $('#distribution_id').append('<option value="' + v.distribution_id + '">' + v.distribution_name + '</option>');
                            });
                        }
                    }
                });
            }
        });

    });



    //选择部门事件 -- 销售员
    $(window).ready(function() {


        $('#searchPanels').find('li').click(function() {

            var departmentID = $(this).attr('departmentID');
            if (departmentID > 0) {

                E.ajax_get({
                    url: '/invokingAjax-backend/company/company.ajax?operFlg=2',
                    data: {
                        departmentID: departmentID
                    },
                    call: function( o ) {

                        if (o.code == 200) {

                            var html = '<option value="">请选择</option>';
                            if ( o.data ) {
                                $.each( o.data, function( k, v ) {
                                    html += '<option value="' + v.userID + '">' + v.trueName + '</option>';
                                });
                            }
                            $('#userID').html(html);

                        } else {

                            E.alert( o.message);

                        }

                    }
                });

            } else {
                var html = '<option value="">请选择</option>';
                $('#userID').html(html);
            }

        });

    });

</script>

</body>
</html>